#include <stdio.h>


#include "tx_api.h"
#include "nx_api.h"
#include "tls_test_utility.h"
#include "nx_secure_tls_api.h"
#include "nx_secure_x509.h"



static const UCHAR example_com_der[] = {
    0x30, 0x82, 0x03, 0x25, 0x30, 0x82, 0x02, 0x0d, 0x02, 0x09, 0x00, 0xe8,
    0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x54, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x1e,
    0x17, 0x0d, 0x31, 0x37, 0x31, 0x31, 0x30, 0x39, 0x30, 0x37, 0x33, 0x37,
    0x35, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x38, 0x32, 0x39, 0x30,
    0x37, 0x33, 0x37, 0x35, 0x36, 0x5a, 0x30, 0x57, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31,
    0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45,
    0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b,
    0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30,
    0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
    0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30,
    0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb5, 0xb8, 0x43, 0xe0,
    0x33, 0x31, 0x80, 0x31, 0xe6, 0x0d, 0x65, 0x84, 0x40, 0x34, 0xe1, 0xfb,
    0x69, 0xa6, 0x23, 0xbd, 0x35, 0xcd, 0xde, 0xbc, 0x0f, 0x1a, 0xd4, 0x27,
    0x44, 0xee, 0x03, 0xdf, 0xc5, 0xcc, 0x2c, 0x22, 0xda, 0xe1, 0x67, 0x3b,
    0x6b, 0xa1, 0xa9, 0x97, 0x93, 0xa1, 0x58, 0x1c, 0x23, 0x1b, 0x2c, 0xf0,
    0xd0, 0xee, 0x3f, 0x32, 0xbf, 0x23, 0x23, 0xf9, 0x22, 0x56, 0xa2, 0x1e,
    0x31, 0xfd, 0x22, 0x02, 0x9a, 0x12, 0x83, 0x2c, 0x34, 0xf4, 0x32, 0xf2,
    0xb4, 0x5f, 0x13, 0x77, 0x71, 0x49, 0x8f, 0xcb, 0x52, 0xb4, 0xf5, 0xd6,
    0xb2, 0xd5, 0xd6, 0x05, 0x92, 0x3d, 0x53, 0x85, 0x7d, 0x36, 0x5e, 0x4d,
    0xd4, 0x5d, 0xc0, 0xcd, 0x6d, 0xd8, 0xf3, 0xc8, 0x72, 0xa2, 0x4a, 0xf9,
    0x8b, 0x1a, 0x12, 0xa4, 0x89, 0xc2, 0xcd, 0x86, 0xf9, 0x50, 0x6c, 0xc6,
    0x37, 0x36, 0x3e, 0xeb, 0xb4, 0xb5, 0x7c, 0xda, 0x14, 0xf8, 0x05, 0x51,
    0x5c, 0x90, 0x13, 0xc2, 0xa8, 0x82, 0xac, 0x13, 0x8b, 0x29, 0x66, 0x4c,
    0x51, 0xde, 0xf4, 0x6f, 0xfc, 0x49, 0x95, 0x68, 0x36, 0xbc, 0x69, 0xe4,
    0xe0, 0xb9, 0xb7, 0x49, 0xcb, 0x99, 0x8c, 0x51, 0xc1, 0x82, 0x4b, 0x94,
    0xed, 0x83, 0x6e, 0xc8, 0xc6, 0x4c, 0x43, 0x47, 0x6d, 0x4f, 0xce, 0x10,
    0x54, 0x06, 0xd7, 0xa9, 0x2b, 0x29, 0x77, 0x53, 0xd3, 0xfb, 0xd3, 0x32,
    0xb9, 0x6d, 0x73, 0x22, 0x0d, 0xa8, 0xcd, 0x1a, 0xf9, 0x8e, 0x51, 0xeb,
    0x12, 0x37, 0xee, 0xc4, 0xe4, 0x21, 0xf6, 0x6a, 0x4e, 0x14, 0x9c, 0xcc,
    0xad, 0x02, 0xbe, 0x21, 0x99, 0x7d, 0x56, 0xd5, 0xb0, 0x13, 0x0e, 0x3c,
    0x0d, 0x6e, 0x8e, 0xb8, 0x3c, 0xb8, 0x5c, 0xff, 0x64, 0xe2, 0xf6, 0xd6,
    0xa7, 0x06, 0x03, 0x77, 0x0d, 0xe4, 0x5e, 0xe4, 0x50, 0x26, 0x28, 0x7f,
    0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
    0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
    0x00, 0x8d, 0xb7, 0xf9, 0x4f, 0xe3, 0x9b, 0x25, 0xdd, 0x49, 0x69, 0x37,
    0xae, 0xca, 0xd6, 0x18, 0x4a, 0x96, 0x63, 0x83, 0x9d, 0x3d, 0xec, 0xeb,
    0x62, 0x97, 0xeb, 0xfc, 0x91, 0x5f, 0xf4, 0x2b, 0x62, 0x39, 0x11, 0xd4,
    0xb7, 0x31, 0x75, 0x1b, 0x08, 0xda, 0x4e, 0xa4, 0xf8, 0x2c, 0x08, 0x61,
    0x80, 0x3e, 0x1d, 0x18, 0x72, 0x71, 0x9b, 0x78, 0xea, 0x12, 0x79, 0xa6,
    0x70, 0xc1, 0x40, 0x06, 0x26, 0xee, 0xaf, 0x26, 0xd7, 0xa2, 0x79, 0x32,
    0xfa, 0x4f, 0xcc, 0x9a, 0x1d, 0xb9, 0xdf, 0x57, 0x3c, 0x0f, 0x2c, 0x12,
    0x7b, 0xa7, 0x5f, 0xd3, 0x38, 0x40, 0x33, 0x8c, 0xfa, 0x16, 0x8f, 0x10,
    0xf0, 0xe3, 0x81, 0x35, 0x0d, 0x2e, 0x38, 0xd8, 0x82, 0x23, 0xa7, 0xdb,
    0x9e, 0x7c, 0x78, 0xb9, 0x6b, 0x52, 0xcc, 0x0d, 0x40, 0x22, 0xbf, 0x5d,
    0x15, 0x97, 0xcf, 0x8f, 0xf3, 0x38, 0x73, 0x25, 0x85, 0x5f, 0x07, 0xbd,
    0x11, 0x81, 0x03, 0x1f, 0xc0, 0x82, 0xe4, 0xcb, 0xaa, 0xe2, 0x3a, 0xa8,
    0x6b, 0x92, 0x41, 0xaa, 0xa1, 0xb6, 0xe1, 0x23, 0x44, 0xca, 0xcc, 0xa2,
    0x43, 0x5a, 0xc1, 0xae, 0x62, 0x32, 0x8d, 0x85, 0x64, 0xc3, 0x0c, 0x0c,
    0x38, 0x97, 0x47, 0x08, 0xbb, 0x25, 0x78, 0xc3, 0x8f, 0x38, 0xfe, 0x73,
    0x26, 0xf9, 0xec, 0x72, 0x5c, 0x14, 0xe3, 0xd7, 0x55, 0x5b, 0x6c, 0xf5,
    0x16, 0xb2, 0x15, 0xe7, 0x35, 0x54, 0x45, 0xbb, 0x8a, 0x75, 0xeb, 0x84,
    0xd5, 0xb7, 0xdd, 0xab, 0x65, 0xe9, 0x82, 0x6f, 0x4e, 0xd7, 0x11, 0x99,
    0x09, 0x83, 0x4c, 0x40, 0xd8, 0xde, 0x8e, 0x6f, 0xfe, 0xd2, 0x78, 0x70,
    0x17, 0x9d, 0x41, 0x0d, 0x50, 0xa2, 0x6a, 0xe4, 0xcc, 0xb3, 0xf9, 0x34,
    0x4a, 0x7f, 0x43, 0x2a, 0x48, 0x79, 0x74, 0xbc, 0xe9, 0x3d, 0x48, 0x37,
    0x76, 0xed, 0xd9, 0x7b, 0x80
};

static const UCHAR example_com_localtime_der[] = {
    0x30, 0x82, 0x03, 0x29, 0x30, 0x82, 0x02, 0x11, 0x02, 0x09, 0x00, 0xe8,
    0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x54, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x22,
    0x17, 0x0f, 0x39, 0x39, 0x31, 0x32, 0x31, 0x31, 0x31, 0x30, 0x30, 0x39,
    0x2b, 0x30, 0x38, 0x30, 0x30, 0x17, 0x0f, 0x30, 0x34, 0x30, 0x32, 0x30,
    0x33, 0x30, 0x34, 0x30, 0x35, 0x2d, 0x30, 0x31, 0x33, 0x30, 0x30, 0x57,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
    0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
    0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00,
    0xb5, 0xb8, 0x43, 0xe0, 0x33, 0x31, 0x80, 0x31, 0xe6, 0x0d, 0x65, 0x84,
    0x40, 0x34, 0xe1, 0xfb, 0x69, 0xa6, 0x23, 0xbd, 0x35, 0xcd, 0xde, 0xbc,
    0x0f, 0x1a, 0xd4, 0x27, 0x44, 0xee, 0x03, 0xdf, 0xc5, 0xcc, 0x2c, 0x22,
    0xda, 0xe1, 0x67, 0x3b, 0x6b, 0xa1, 0xa9, 0x97, 0x93, 0xa1, 0x58, 0x1c,
    0x23, 0x1b, 0x2c, 0xf0, 0xd0, 0xee, 0x3f, 0x32, 0xbf, 0x23, 0x23, 0xf9,
    0x22, 0x56, 0xa2, 0x1e, 0x31, 0xfd, 0x22, 0x02, 0x9a, 0x12, 0x83, 0x2c,
    0x34, 0xf4, 0x32, 0xf2, 0xb4, 0x5f, 0x13, 0x77, 0x71, 0x49, 0x8f, 0xcb,
    0x52, 0xb4, 0xf5, 0xd6, 0xb2, 0xd5, 0xd6, 0x05, 0x92, 0x3d, 0x53, 0x85,
    0x7d, 0x36, 0x5e, 0x4d, 0xd4, 0x5d, 0xc0, 0xcd, 0x6d, 0xd8, 0xf3, 0xc8,
    0x72, 0xa2, 0x4a, 0xf9, 0x8b, 0x1a, 0x12, 0xa4, 0x89, 0xc2, 0xcd, 0x86,
    0xf9, 0x50, 0x6c, 0xc6, 0x37, 0x36, 0x3e, 0xeb, 0xb4, 0xb5, 0x7c, 0xda,
    0x14, 0xf8, 0x05, 0x51, 0x5c, 0x90, 0x13, 0xc2, 0xa8, 0x82, 0xac, 0x13,
    0x8b, 0x29, 0x66, 0x4c, 0x51, 0xde, 0xf4, 0x6f, 0xfc, 0x49, 0x95, 0x68,
    0x36, 0xbc, 0x69, 0xe4, 0xe0, 0xb9, 0xb7, 0x49, 0xcb, 0x99, 0x8c, 0x51,
    0xc1, 0x82, 0x4b, 0x94, 0xed, 0x83, 0x6e, 0xc8, 0xc6, 0x4c, 0x43, 0x47,
    0x6d, 0x4f, 0xce, 0x10, 0x54, 0x06, 0xd7, 0xa9, 0x2b, 0x29, 0x77, 0x53,
    0xd3, 0xfb, 0xd3, 0x32, 0xb9, 0x6d, 0x73, 0x22, 0x0d, 0xa8, 0xcd, 0x1a,
    0xf9, 0x8e, 0x51, 0xeb, 0x12, 0x37, 0xee, 0xc4, 0xe4, 0x21, 0xf6, 0x6a,
    0x4e, 0x14, 0x9c, 0xcc, 0xad, 0x02, 0xbe, 0x21, 0x99, 0x7d, 0x56, 0xd5,
    0xb0, 0x13, 0x0e, 0x3c, 0x0d, 0x6e, 0x8e, 0xb8, 0x3c, 0xb8, 0x5c, 0xff,
    0x64, 0xe2, 0xf6, 0xd6, 0xa7, 0x06, 0x03, 0x77, 0x0d, 0xe4, 0x5e, 0xe4,
    0x50, 0x26, 0x28, 0x7f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06,
    0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
    0x03, 0x82, 0x01, 0x01, 0x00, 0x8d, 0xb7, 0xf9, 0x4f, 0xe3, 0x9b, 0x25,
    0xdd, 0x49, 0x69, 0x37, 0xae, 0xca, 0xd6, 0x18, 0x4a, 0x96, 0x63, 0x83,
    0x9d, 0x3d, 0xec, 0xeb, 0x62, 0x97, 0xeb, 0xfc, 0x91, 0x5f, 0xf4, 0x2b,
    0x62, 0x39, 0x11, 0xd4, 0xb7, 0x31, 0x75, 0x1b, 0x08, 0xda, 0x4e, 0xa4,
    0xf8, 0x2c, 0x08, 0x61, 0x80, 0x3e, 0x1d, 0x18, 0x72, 0x71, 0x9b, 0x78,
    0xea, 0x12, 0x79, 0xa6, 0x70, 0xc1, 0x40, 0x06, 0x26, 0xee, 0xaf, 0x26,
    0xd7, 0xa2, 0x79, 0x32, 0xfa, 0x4f, 0xcc, 0x9a, 0x1d, 0xb9, 0xdf, 0x57,
    0x3c, 0x0f, 0x2c, 0x12, 0x7b, 0xa7, 0x5f, 0xd3, 0x38, 0x40, 0x33, 0x8c,
    0xfa, 0x16, 0x8f, 0x10, 0xf0, 0xe3, 0x81, 0x35, 0x0d, 0x2e, 0x38, 0xd8,
    0x82, 0x23, 0xa7, 0xdb, 0x9e, 0x7c, 0x78, 0xb9, 0x6b, 0x52, 0xcc, 0x0d,
    0x40, 0x22, 0xbf, 0x5d, 0x15, 0x97, 0xcf, 0x8f, 0xf3, 0x38, 0x73, 0x25,
    0x85, 0x5f, 0x07, 0xbd, 0x11, 0x81, 0x03, 0x1f, 0xc0, 0x82, 0xe4, 0xcb,
    0xaa, 0xe2, 0x3a, 0xa8, 0x6b, 0x92, 0x41, 0xaa, 0xa1, 0xb6, 0xe1, 0x23,
    0x44, 0xca, 0xcc, 0xa2, 0x43, 0x5a, 0xc1, 0xae, 0x62, 0x32, 0x8d, 0x85,
    0x64, 0xc3, 0x0c, 0x0c, 0x38, 0x97, 0x47, 0x08, 0xbb, 0x25, 0x78, 0xc3,
    0x8f, 0x38, 0xfe, 0x73, 0x26, 0xf9, 0xec, 0x72, 0x5c, 0x14, 0xe3, 0xd7,
    0x55, 0x5b, 0x6c, 0xf5, 0x16, 0xb2, 0x15, 0xe7, 0x35, 0x54, 0x45, 0xbb,
    0x8a, 0x75, 0xeb, 0x84, 0xd5, 0xb7, 0xdd, 0xab, 0x65, 0xe9, 0x82, 0x6f,
    0x4e, 0xd7, 0x11, 0x99, 0x09, 0x83, 0x4c, 0x40, 0xd8, 0xde, 0x8e, 0x6f,
    0xfe, 0xd2, 0x78, 0x70, 0x17, 0x9d, 0x41, 0x0d, 0x50, 0xa2, 0x6a, 0xe4,
    0xcc, 0xb3, 0xf9, 0x34, 0x4a, 0x7f, 0x43, 0x2a, 0x48, 0x79, 0x74, 0xbc,
    0xe9, 0x3d, 0x48, 0x37, 0x76, 0xed, 0xd9, 0x7b, 0x80
};

static const UCHAR example_com_bad_not_before_der[] = {
    0x30, 0x82, 0x03, 0x23, 0x30, 0x82, 0x02, 0x0b, 0x02, 0x09, 0x00, 0xe8,
    0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x54, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x1c,
    0x17, 0x0d, 0x31, 0x37, 0x31, 0x31, 0x30, 0x39, 0x30, 0x37, 0x33, 0x37,
    0x35, 0x36, 0x44, 0x17, 0x0b, 0x32, 0x30, 0x30, 0x38, 0x32, 0x39, 0x30,
    0x37, 0x33, 0x37, 0x5a, 0x30, 0x57, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
    0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06,
    0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31,
    0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x65, 0x78,
    0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01,
    0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
    0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
    0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb5, 0xb8, 0x43, 0xe0, 0x33, 0x31,
    0x80, 0x31, 0xe6, 0x0d, 0x65, 0x84, 0x40, 0x34, 0xe1, 0xfb, 0x69, 0xa6,
    0x23, 0xbd, 0x35, 0xcd, 0xde, 0xbc, 0x0f, 0x1a, 0xd4, 0x27, 0x44, 0xee,
    0x03, 0xdf, 0xc5, 0xcc, 0x2c, 0x22, 0xda, 0xe1, 0x67, 0x3b, 0x6b, 0xa1,
    0xa9, 0x97, 0x93, 0xa1, 0x58, 0x1c, 0x23, 0x1b, 0x2c, 0xf0, 0xd0, 0xee,
    0x3f, 0x32, 0xbf, 0x23, 0x23, 0xf9, 0x22, 0x56, 0xa2, 0x1e, 0x31, 0xfd,
    0x22, 0x02, 0x9a, 0x12, 0x83, 0x2c, 0x34, 0xf4, 0x32, 0xf2, 0xb4, 0x5f,
    0x13, 0x77, 0x71, 0x49, 0x8f, 0xcb, 0x52, 0xb4, 0xf5, 0xd6, 0xb2, 0xd5,
    0xd6, 0x05, 0x92, 0x3d, 0x53, 0x85, 0x7d, 0x36, 0x5e, 0x4d, 0xd4, 0x5d,
    0xc0, 0xcd, 0x6d, 0xd8, 0xf3, 0xc8, 0x72, 0xa2, 0x4a, 0xf9, 0x8b, 0x1a,
    0x12, 0xa4, 0x89, 0xc2, 0xcd, 0x86, 0xf9, 0x50, 0x6c, 0xc6, 0x37, 0x36,
    0x3e, 0xeb, 0xb4, 0xb5, 0x7c, 0xda, 0x14, 0xf8, 0x05, 0x51, 0x5c, 0x90,
    0x13, 0xc2, 0xa8, 0x82, 0xac, 0x13, 0x8b, 0x29, 0x66, 0x4c, 0x51, 0xde,
    0xf4, 0x6f, 0xfc, 0x49, 0x95, 0x68, 0x36, 0xbc, 0x69, 0xe4, 0xe0, 0xb9,
    0xb7, 0x49, 0xcb, 0x99, 0x8c, 0x51, 0xc1, 0x82, 0x4b, 0x94, 0xed, 0x83,
    0x6e, 0xc8, 0xc6, 0x4c, 0x43, 0x47, 0x6d, 0x4f, 0xce, 0x10, 0x54, 0x06,
    0xd7, 0xa9, 0x2b, 0x29, 0x77, 0x53, 0xd3, 0xfb, 0xd3, 0x32, 0xb9, 0x6d,
    0x73, 0x22, 0x0d, 0xa8, 0xcd, 0x1a, 0xf9, 0x8e, 0x51, 0xeb, 0x12, 0x37,
    0xee, 0xc4, 0xe4, 0x21, 0xf6, 0x6a, 0x4e, 0x14, 0x9c, 0xcc, 0xad, 0x02,
    0xbe, 0x21, 0x99, 0x7d, 0x56, 0xd5, 0xb0, 0x13, 0x0e, 0x3c, 0x0d, 0x6e,
    0x8e, 0xb8, 0x3c, 0xb8, 0x5c, 0xff, 0x64, 0xe2, 0xf6, 0xd6, 0xa7, 0x06,
    0x03, 0x77, 0x0d, 0xe4, 0x5e, 0xe4, 0x50, 0x26, 0x28, 0x7f, 0x02, 0x03,
    0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
    0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8d,
    0xb7, 0xf9, 0x4f, 0xe3, 0x9b, 0x25, 0xdd, 0x49, 0x69, 0x37, 0xae, 0xca,
    0xd6, 0x18, 0x4a, 0x96, 0x63, 0x83, 0x9d, 0x3d, 0xec, 0xeb, 0x62, 0x97,
    0xeb, 0xfc, 0x91, 0x5f, 0xf4, 0x2b, 0x62, 0x39, 0x11, 0xd4, 0xb7, 0x31,
    0x75, 0x1b, 0x08, 0xda, 0x4e, 0xa4, 0xf8, 0x2c, 0x08, 0x61, 0x80, 0x3e,
    0x1d, 0x18, 0x72, 0x71, 0x9b, 0x78, 0xea, 0x12, 0x79, 0xa6, 0x70, 0xc1,
    0x40, 0x06, 0x26, 0xee, 0xaf, 0x26, 0xd7, 0xa2, 0x79, 0x32, 0xfa, 0x4f,
    0xcc, 0x9a, 0x1d, 0xb9, 0xdf, 0x57, 0x3c, 0x0f, 0x2c, 0x12, 0x7b, 0xa7,
    0x5f, 0xd3, 0x38, 0x40, 0x33, 0x8c, 0xfa, 0x16, 0x8f, 0x10, 0xf0, 0xe3,
    0x81, 0x35, 0x0d, 0x2e, 0x38, 0xd8, 0x82, 0x23, 0xa7, 0xdb, 0x9e, 0x7c,
    0x78, 0xb9, 0x6b, 0x52, 0xcc, 0x0d, 0x40, 0x22, 0xbf, 0x5d, 0x15, 0x97,
    0xcf, 0x8f, 0xf3, 0x38, 0x73, 0x25, 0x85, 0x5f, 0x07, 0xbd, 0x11, 0x81,
    0x03, 0x1f, 0xc0, 0x82, 0xe4, 0xcb, 0xaa, 0xe2, 0x3a, 0xa8, 0x6b, 0x92,
    0x41, 0xaa, 0xa1, 0xb6, 0xe1, 0x23, 0x44, 0xca, 0xcc, 0xa2, 0x43, 0x5a,
    0xc1, 0xae, 0x62, 0x32, 0x8d, 0x85, 0x64, 0xc3, 0x0c, 0x0c, 0x38, 0x97,
    0x47, 0x08, 0xbb, 0x25, 0x78, 0xc3, 0x8f, 0x38, 0xfe, 0x73, 0x26, 0xf9,
    0xec, 0x72, 0x5c, 0x14, 0xe3, 0xd7, 0x55, 0x5b, 0x6c, 0xf5, 0x16, 0xb2,
    0x15, 0xe7, 0x35, 0x54, 0x45, 0xbb, 0x8a, 0x75, 0xeb, 0x84, 0xd5, 0xb7,
    0xdd, 0xab, 0x65, 0xe9, 0x82, 0x6f, 0x4e, 0xd7, 0x11, 0x99, 0x09, 0x83,
    0x4c, 0x40, 0xd8, 0xde, 0x8e, 0x6f, 0xfe, 0xd2, 0x78, 0x70, 0x17, 0x9d,
    0x41, 0x0d, 0x50, 0xa2, 0x6a, 0xe4, 0xcc, 0xb3, 0xf9, 0x34, 0x4a, 0x7f,
    0x43, 0x2a, 0x48, 0x79, 0x74, 0xbc, 0xe9, 0x3d, 0x48, 0x37, 0x76, 0xed,
    0xd9, 0x7b, 0x80
};

static const UCHAR example_com_bad_not_after_der[] = {
    0x30, 0x82, 0x03, 0x23, 0x30, 0x82, 0x02, 0x0b, 0x02, 0x09, 0x00, 0xe8,
    0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x54, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x1c,
    0x17, 0x0b, 0x31, 0x37, 0x31, 0x31, 0x30, 0x39, 0x30, 0x37, 0x33, 0x37,
    0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x38, 0x32, 0x39, 0x30, 0x37, 0x33,
    0x37, 0x35, 0x36, 0x20, 0x30, 0x57, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
    0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06,
    0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31,
    0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x65, 0x78,
    0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01,
    0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
    0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
    0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb5, 0xb8, 0x43, 0xe0, 0x33, 0x31,
    0x80, 0x31, 0xe6, 0x0d, 0x65, 0x84, 0x40, 0x34, 0xe1, 0xfb, 0x69, 0xa6,
    0x23, 0xbd, 0x35, 0xcd, 0xde, 0xbc, 0x0f, 0x1a, 0xd4, 0x27, 0x44, 0xee,
    0x03, 0xdf, 0xc5, 0xcc, 0x2c, 0x22, 0xda, 0xe1, 0x67, 0x3b, 0x6b, 0xa1,
    0xa9, 0x97, 0x93, 0xa1, 0x58, 0x1c, 0x23, 0x1b, 0x2c, 0xf0, 0xd0, 0xee,
    0x3f, 0x32, 0xbf, 0x23, 0x23, 0xf9, 0x22, 0x56, 0xa2, 0x1e, 0x31, 0xfd,
    0x22, 0x02, 0x9a, 0x12, 0x83, 0x2c, 0x34, 0xf4, 0x32, 0xf2, 0xb4, 0x5f,
    0x13, 0x77, 0x71, 0x49, 0x8f, 0xcb, 0x52, 0xb4, 0xf5, 0xd6, 0xb2, 0xd5,
    0xd6, 0x05, 0x92, 0x3d, 0x53, 0x85, 0x7d, 0x36, 0x5e, 0x4d, 0xd4, 0x5d,
    0xc0, 0xcd, 0x6d, 0xd8, 0xf3, 0xc8, 0x72, 0xa2, 0x4a, 0xf9, 0x8b, 0x1a,
    0x12, 0xa4, 0x89, 0xc2, 0xcd, 0x86, 0xf9, 0x50, 0x6c, 0xc6, 0x37, 0x36,
    0x3e, 0xeb, 0xb4, 0xb5, 0x7c, 0xda, 0x14, 0xf8, 0x05, 0x51, 0x5c, 0x90,
    0x13, 0xc2, 0xa8, 0x82, 0xac, 0x13, 0x8b, 0x29, 0x66, 0x4c, 0x51, 0xde,
    0xf4, 0x6f, 0xfc, 0x49, 0x95, 0x68, 0x36, 0xbc, 0x69, 0xe4, 0xe0, 0xb9,
    0xb7, 0x49, 0xcb, 0x99, 0x8c, 0x51, 0xc1, 0x82, 0x4b, 0x94, 0xed, 0x83,
    0x6e, 0xc8, 0xc6, 0x4c, 0x43, 0x47, 0x6d, 0x4f, 0xce, 0x10, 0x54, 0x06,
    0xd7, 0xa9, 0x2b, 0x29, 0x77, 0x53, 0xd3, 0xfb, 0xd3, 0x32, 0xb9, 0x6d,
    0x73, 0x22, 0x0d, 0xa8, 0xcd, 0x1a, 0xf9, 0x8e, 0x51, 0xeb, 0x12, 0x37,
    0xee, 0xc4, 0xe4, 0x21, 0xf6, 0x6a, 0x4e, 0x14, 0x9c, 0xcc, 0xad, 0x02,
    0xbe, 0x21, 0x99, 0x7d, 0x56, 0xd5, 0xb0, 0x13, 0x0e, 0x3c, 0x0d, 0x6e,
    0x8e, 0xb8, 0x3c, 0xb8, 0x5c, 0xff, 0x64, 0xe2, 0xf6, 0xd6, 0xa7, 0x06,
    0x03, 0x77, 0x0d, 0xe4, 0x5e, 0xe4, 0x50, 0x26, 0x28, 0x7f, 0x02, 0x03,
    0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
    0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8d,
    0xb7, 0xf9, 0x4f, 0xe3, 0x9b, 0x25, 0xdd, 0x49, 0x69, 0x37, 0xae, 0xca,
    0xd6, 0x18, 0x4a, 0x96, 0x63, 0x83, 0x9d, 0x3d, 0xec, 0xeb, 0x62, 0x97,
    0xeb, 0xfc, 0x91, 0x5f, 0xf4, 0x2b, 0x62, 0x39, 0x11, 0xd4, 0xb7, 0x31,
    0x75, 0x1b, 0x08, 0xda, 0x4e, 0xa4, 0xf8, 0x2c, 0x08, 0x61, 0x80, 0x3e,
    0x1d, 0x18, 0x72, 0x71, 0x9b, 0x78, 0xea, 0x12, 0x79, 0xa6, 0x70, 0xc1,
    0x40, 0x06, 0x26, 0xee, 0xaf, 0x26, 0xd7, 0xa2, 0x79, 0x32, 0xfa, 0x4f,
    0xcc, 0x9a, 0x1d, 0xb9, 0xdf, 0x57, 0x3c, 0x0f, 0x2c, 0x12, 0x7b, 0xa7,
    0x5f, 0xd3, 0x38, 0x40, 0x33, 0x8c, 0xfa, 0x16, 0x8f, 0x10, 0xf0, 0xe3,
    0x81, 0x35, 0x0d, 0x2e, 0x38, 0xd8, 0x82, 0x23, 0xa7, 0xdb, 0x9e, 0x7c,
    0x78, 0xb9, 0x6b, 0x52, 0xcc, 0x0d, 0x40, 0x22, 0xbf, 0x5d, 0x15, 0x97,
    0xcf, 0x8f, 0xf3, 0x38, 0x73, 0x25, 0x85, 0x5f, 0x07, 0xbd, 0x11, 0x81,
    0x03, 0x1f, 0xc0, 0x82, 0xe4, 0xcb, 0xaa, 0xe2, 0x3a, 0xa8, 0x6b, 0x92,
    0x41, 0xaa, 0xa1, 0xb6, 0xe1, 0x23, 0x44, 0xca, 0xcc, 0xa2, 0x43, 0x5a,
    0xc1, 0xae, 0x62, 0x32, 0x8d, 0x85, 0x64, 0xc3, 0x0c, 0x0c, 0x38, 0x97,
    0x47, 0x08, 0xbb, 0x25, 0x78, 0xc3, 0x8f, 0x38, 0xfe, 0x73, 0x26, 0xf9,
    0xec, 0x72, 0x5c, 0x14, 0xe3, 0xd7, 0x55, 0x5b, 0x6c, 0xf5, 0x16, 0xb2,
    0x15, 0xe7, 0x35, 0x54, 0x45, 0xbb, 0x8a, 0x75, 0xeb, 0x84, 0xd5, 0xb7,
    0xdd, 0xab, 0x65, 0xe9, 0x82, 0x6f, 0x4e, 0xd7, 0x11, 0x99, 0x09, 0x83,
    0x4c, 0x40, 0xd8, 0xde, 0x8e, 0x6f, 0xfe, 0xd2, 0x78, 0x70, 0x17, 0x9d,
    0x41, 0x0d, 0x50, 0xa2, 0x6a, 0xe4, 0xcc, 0xb3, 0xf9, 0x34, 0x4a, 0x7f,
    0x43, 0x2a, 0x48, 0x79, 0x74, 0xbc, 0xe9, 0x3d, 0x48, 0x37, 0x76, 0xed,
    0xd9, 0x7b, 0x80
};


static TX_THREAD thread_0;

static VOID thread_0_entry(ULONG thread_input);
static NX_SECURE_X509_CERT example_certificate;
static NX_SECURE_X509_CERT localtime_certificate;
static NX_SECURE_X509_CERT bad_not_before_certificate;
static NX_SECURE_X509_CERT bad_not_after_certificate;


#ifdef CTEST
void test_application_define(void *first_unused_memory);
void test_application_define(void *first_unused_memory)
#else
void nx_secure_x509_expiration_check_test_application_define(void *first_unused_memory)
#endif
{
    tx_thread_create(&thread_0, "Thread 0", thread_0_entry, 0,
        first_unused_memory, 4096,
        16, 16, 4, TX_AUTO_START);
}

static VOID thread_0_entry(ULONG thread_input)
{
UINT status;
USHORT backup;

    /* Print out test information banner.  */
    printf("NetX Secure Test:   X509 expiration check test.........................");

    /* Test certificate with Zulu time 171109073756Z to 200829073756Z. */
    status = nx_secure_x509_certificate_initialize(&example_certificate, (UCHAR*)example_com_der, sizeof(example_com_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&example_certificate, 1510213076);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&example_certificate, 1510213075);
    EXPECT_EQ(NX_SECURE_X509_CERTIFICATE_NOT_YET_VALID, status);

    status = _nx_secure_x509_expiration_check(&example_certificate, 1598686676);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&example_certificate, 1598686677);
    EXPECT_EQ(NX_SECURE_X509_CERTIFICATE_EXPIRED, status);


    /* Test certificate with local time offset 9912111009+0800 to 0402030405-0130. */
    status = nx_secure_x509_certificate_initialize(&localtime_certificate, (UCHAR*)example_com_localtime_der, sizeof(example_com_localtime_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&localtime_certificate, 944878140);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&localtime_certificate, 944878139);
    EXPECT_EQ(NX_SECURE_X509_CERTIFICATE_NOT_YET_VALID, status);

    status = _nx_secure_x509_expiration_check(&localtime_certificate, 1075786500);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&localtime_certificate, 1075786501);
    EXPECT_EQ(NX_SECURE_X509_CERTIFICATE_EXPIRED, status);


    /* Test certificate with bad "not before" field 171109073756D. */
    status = nx_secure_x509_certificate_initialize(&bad_not_before_certificate, (UCHAR*)example_com_bad_not_before_der, sizeof(example_com_bad_not_before_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&bad_not_before_certificate, 1510213076);
    EXPECT_EQ(NX_SECURE_X509_INVALID_DATE_FORMAT, status);


    /* Test certificate with bad "not after" field 200829073756 . */
    status = nx_secure_x509_certificate_initialize(&bad_not_after_certificate, (UCHAR*)example_com_bad_not_after_der, sizeof(example_com_bad_not_after_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = _nx_secure_x509_expiration_check(&bad_not_after_certificate, 1598686676);
    EXPECT_EQ(NX_SECURE_X509_INVALID_DATE_FORMAT, status);


    /* Invalid time format. */
    backup = localtime_certificate.nx_secure_x509_validity_format;
    localtime_certificate.nx_secure_x509_validity_format = 0xff;
    status = _nx_secure_x509_expiration_check(&localtime_certificate, 944878140);
    localtime_certificate.nx_secure_x509_validity_format = backup;
    EXPECT_EQ(NX_SECURE_X509_INVALID_DATE_FORMAT, status);

    printf("SUCCESS!\n");
    test_control_return(0);

}
